package com.zr.qkchat.data.service;

import com.zr.qkchat.data.model.User;
import com.zr.qkchat.data.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component("userService")
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public User getUserByName(String name) {
        return userRepository.findByName(name);
    }

    @Override
    public User getUserById(String uid) {
        return userRepository.findOne(uid);
    }

    @Override
    public boolean create(User user) {
        user.setUid(System.currentTimeMillis()+"");
        User u = userRepository.save(user);
        return u!=null;
    }

}
